#include "gamehall.h"
#include "ui_gamehall.h"
#include<QPainter>
#include<QPixmap>
#include<QIcon>
#include<QPushButton>
#include<QSound>
#include"gameselect.h"

GameHall::GameHall(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::GameHall)
{
    ui->setupUi(this);

    //窗口大小
    this->setFixedSize(1000,900);
    //设置窗口图标
    this->setWindowIcon(QIcon(":/Snake icon/snake.png"));
    //设置窗口标题
    this->setWindowTitle("贪吃蛇游戏");

    QFont font("微软雅黑",20);
    QPushButton* startbutton=new QPushButton(this);
    startbutton->move(450,800);
    startbutton->setText("开始游戏");
    startbutton->setFont(font);
    startbutton->setStyleSheet("QPushButton{border:0px;}");

    //创建开始游戏后跳转的窗口
    Gameselect* select=new Gameselect;

    connect(startbutton,&QPushButton::clicked,[=](){
        this->close();
        select->setGeometry(this->geometry());//设置窗口大小和this（也就是当前窗口一样大小）
        select->show();
        QSound::play(":/Snake icon/startgame_click.wav");//设置点击开始游戏按钮音效，需要在.pro文件当中加上multimedia
    });

}

GameHall::~GameHall()
{
    delete ui;
}

void GameHall::paintEvent(QPaintEvent *event)
{
    //初始化画家
    QPainter painter(this);
    //初始化绘图设备
    QPixmap pixmap(":/Snake icon/snake_home_page.png");

    painter.drawPixmap(0,0,this->width(),this->height(),pixmap);

}

